package concurrent.producerconsumer;

import java.util.concurrent.LinkedBlockingQueue;

/**
 * Author: Jason Wu
 * Date  : 2013-12-19
 */
public class Producer implements Runnable {
    private final LinkedBlockingQueue<Task> queue;
    private int count;

    public Producer(LinkedBlockingQueue<Task> queue, int count) {
        this.queue = queue;
        this.count = count;
    }

    @Override
    public void run() {
        for (int taskId = 0; taskId < count; taskId++) {
            synchronized (queue) {
                queue.add(new Task(taskId));
                queue.notifyAll();
            }
        }
    }
}
